/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import entities.Medium;
import entities.Movie;
import javax.swing.AbstractListModel;
import javax.swing.DefaultListModel;
import javax.swing.JList;

/**
 *
 * @author Lucyia
 */
public class SearchResultsModel extends AbstractListModel<Movie>{
    
    private JList jList;
    private DefaultListModel jListModel = new DefaultListModel();
    
    public SearchResultsModel() {
        jList = new JList(jListModel);               
    }
    
    public void addMovieToJList(Movie movie) {        
        jListModel.addElement(movie);  
        int lastRow = jList.getModel().getSize();
        fireContentsChanged(jListModel, 0, lastRow);
    }
    
    public void clearJList() {
        jListModel = new DefaultListModel();
        jList = new JList(jListModel);       
    }
    
    @Override
    public int getSize() {
        return jList.getModel().getSize();
    }

    @Override
    public Movie getElementAt(int i) {
        return (Movie) jList.getModel().getElementAt(i);
    }
    
}
